<?php

 
Zend_Loader::loadClass("BaseDBRows");
Zend_Loader::loadClass("Training");
class Trainings extends BaseDBRows
{
	protected function setUp()
	{
		$this->_tableName = Training::_tablename;
	}
	
	public function getTrainingsByOrgId($orgId,$trainingId=0) 
	{
		Zend_Loader::loadClass("Skill");
		Zend_Loader::loadClass("QueryCreator");
		
		$query = new QueryCreator();
		$query->addSelect("t.*, s.skill");
		$query->addFrom($this->_tableName . " as t ");
		$query->addJoin(" left join " . Skill::_tablename . " s on t.skill_id = s.skill_id ");
		$query->addWhere(" t.org_id = " . $orgId);
		
		if(isset($trainingId) && $trainingId > 0) {
			$query->addWhere(" t.training_id = " . $trainingId);	
		}
		
		$db = DBCon::instance();
		// echo  $query->createSQL();die();
		$result = $db->executeQuery($query->createSQL());
		return $result;
		
	}
		
}
?>